Root Zanli
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
o5t6x7pgljbm
/
www
/
admin
/
app
/
Models
/
Filename :
ProductImage.php
back
Copy
<?php namespace App\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Casts\Attribute; use Config; class ProductImage extends Model { protected $table = 'product_images'; protected $primaryKey = 'product_image_id'; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'product_id', 'image_name', 'updated_at', 'created_at' ]; protected function imageName(): Attribute { return Attribute::make( get: fn (string $value) => Config::get('constants.app.api-product-image-url').$value, ); } public function getOriginalImageName(){ return $this->getAttributes()['image_name']; } public function cloneProductImage(Product $newProduct){ $excludeColumns = ['updated_at']; $clone = $this->replicate(); $clone->created_at = null; $clone->updated_at = null; //set new values $clone->product_id = $newProduct->product_id; $clone->created_at = Carbon::now(); $clone->updated_at = Carbon::now(); $clone->save(); return $clone; } }